package com.eastfair.enums;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 场景类型枚举类
 *
 * </p>
 *
 * @author ligang
 * @date 2021-07-29
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "TerminalTypeEnum", description = "场景类型 #{APP:app;PC:PC;MINI_PROGRAMS:微信小程序-枚举")
public enum TerminalTypeEnum implements BaseEnum {

    /**
     * app="app"
     */
    APP("app"),
    /**
     * PC="PC"
     */
    PC("pc"),
    /**
     * MINI_PROGRAMS="微信小程序"
     */
    MINI_PROGRAMS("微信小程序"),
    ;
    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static TerminalTypeEnum match(String val, TerminalTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static TerminalTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(TerminalTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "场景类型", allowableValues = "APP,PC,WECHAT", example = "APP,PC,WECHAT")
    public String getCode() {
        return this.name();
    }

}
